<template>
  <div>
  <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <div><a class="navbar-brand" href="index.html" style="font-size:32px;">尚筹网-创意产品众筹平台</a></div>
      </div>
    </div>
  </nav>

  <div class="container">
    <h1 id="error" style="color:red" v-text="errormsg"></h1>
    <form id="loginform" class="form-signin" role="form">
      <h2 class="form-signin-heading"><i class="glyphicon glyphicon-user"></i> 用户登录</h2>
      <div class="form-group has-success has-feedback">
        <input type="text" class="form-control" id="loginacct" v-model="loginacct" placeholder="请输入登录账号" autofocus>
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-success has-feedback">
        <input type="text" class="form-control" id="userpswd" v-model="userpswd" placeholder="请输入登录密码" style="margin-top:10px;">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-success has-feedback">
        <select class="form-control" v-model="Identityid" >

          <option value="member">会员</option>
          <option value="user">管理</option>
        </select>
      </div>
      <div class="checkbox">
        <label>
          <input type="checkbox" value="remember-me"> 记住我
        </label>
        <br>
        <label>
          忘记密码
        </label>
        <label style="float:right">
          <a href="reg.html">我要注册</a>
        </label>
      </div>
      <a class="btn btn-lg btn-success btn-block" @click="dologin()" > 登录</a>
    </form>
  </div>
  </div>
</template>

<script>
import axios from 'axios'
import constval from '../../utils/constval'

export default {
  data () {
    return {
      loginacct: '',
      userpswd: '',
      Identityid: '',
      errormsg: ''
    }
  },
  methods: {
    dologin () {
      const loginacct = this.loginacct
      const userpswd = this.userpswd
      if (loginacct === '') {
        this.$layer.msg('用户名不能为空', {time: 1000, icon: 5, shift: 6}, function () {

        })
        return
      }
      if (userpswd === '') {
        this.$layer.msg('登录密码不能为空', {time: 1000, icon: 5, shift: 6}, function () {

        })
        return
      }

      // 发ajax请求进行搜索
      axios.get('/api/doLogin/' + loginacct + '/' + userpswd).then((response) => {
        var res = response.data
        let user = res.data
        if (res.success) {
          // 路由跳转
          constval.save(user)
          this.$router.push('/layout')
        } else {
          this.errormsg = res.msg
        }
      }).catch(function (error) {
        console.log(error)
      })
    }
  }
}
</script>

<style>

</style>
